import java.util.HashMap;
import java.util.HashSet;

public class Solution3 {
    public int numJewelsInStones(String jewels, String stones) {
        char[] jewelChars = jewels.toCharArray();//宝石
        char[] stonesChars = stones.toCharArray();//石头
        int count = 0;
        HashMap<Character,Integer> map=new HashMap<>();
        for(int i = 0; i < stonesChars.length; i++){
            if(map.containsKey(stonesChars[i])){
                map.put(stonesChars[i],map.get(stonesChars[i])+1);
            }else{
                map.put(stonesChars[i],1);
            }
        }
        for(int i = 0; i<jewelChars.length; i++){
            if(map.containsKey(jewelChars[i])){
                count+=map.get(jewelChars[i]);
            }
        }
        return count;
    }
}
